home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / ipdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-07  |  1.9 KB  |  84 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "internet.h"
  6. #include "ip.h"
  7. #include "trace.h"
  8. #include "netuser.h"
  9.  
  10. void
  11. ip_dump(fp,bpp,check)
  12. FILE *fp;
  13. struct mbuf **bpp;
  14. int check;
  15. {
  16.     struct ip ip;
  17.     int16 ip_len, length, csum;
  18.  
  19.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  20.         return;
  21.  
  22.     /* Sneak peek at IP header and find length */
  23.     if(((ip_len = ((*bpp)->data[0] & 0xf) << 2)) < IPLEN) {
  24.         trprintf(fp,"IP: bad header\n");
  25.         return;
  26.     }
  27.     csum = (check == 1) ? cksum(NULLHEADER,*bpp,ip_len) : 0;
  28.  
  29.     ntohip(&ip,bpp);    /* Can't fail, we've already checked ihl */
  30.  
  31.     /* Trim data segment if necessary. */
  32.     length = ip.length - ip_len;    /* Length of data portion */
  33.     trim_mbuf(bpp,length);
  34.     textattr(LIGHTGREEN);
  35.     trprintf(fp,"IP: len %u %s",ip.length,inet_ntoa(ip.source));
  36.     trprintf(fp,"->%s ihl %u ttl %u",
  37.         inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
  38.     if(ip.tos != 0)
  39.         trprintf(fp," tos %u",uchar(ip.tos));
  40.     if(ip.offset != 0 || ip.flags.mf)
  41.         trprintf(fp," id %u offs %u",ip.id,ip.offset);
  42.     if(ip.flags.df)
  43.         trprintf(fp," DF");
  44.     if(ip.flags.mf){
  45.         trprintf(fp," MF");
  46.         check = 0;    /* Bypass host-level checksum verify */
  47.     }
  48.     if(ip.flags.congest)
  49.         trprintf(fp," CE");
  50.     if(csum)
  51.         trprintf(fp," CHECKSUM ERROR (%u)",csum);
  52.  
  53.     if(ip.offset != 0){
  54.         trprintf(fp,"\n");
  55.         return;
  56.     }
  57.     trprintf(fp," prot ");
  58.     switch(uchar(ip.protocol)){
  59.     case IP_PTCL:
  60.         trprintf(fp,"IP\n");
  61.         ip_dump(fp,bpp,check);
  62.         break;
  63.     case TCP_PTCL:
  64.         trprintf(fp,"TCP\n");
  65.         tcp_dump(fp,bpp,ip.source,ip.dest,check);
  66.         break;
  67.     case UDP_PTCL:
  68.         trprintf(fp,"UDP\n");
  69.         udp_dump(fp,bpp,ip.source,ip.dest,check);
  70.         break;
  71.     case ICMP_PTCL:
  72.         trprintf(fp,"ICMP\n");
  73.         icmp_dump(fp,bpp,ip.source,ip.dest,check);
  74.         break;
  75.     case AX25_PTCL:
  76.         trprintf(fp,"AX25\n");
  77.         ax25_dump(fp,bpp,check);
  78.         break;
  79.     default:
  80.         trprintf(fp,"%u\n",uchar(ip.protocol));
  81.         break;
  82.     }
  83. }
  84.